package com.gzh.teaching.controller;

import com.gzh.core.model.vo.Result;
import com.gzh.core.service.CheckToken;
import com.gzh.core.util.RequestContextUtil;
import com.gzh.teaching.model.vo.*;
import com.gzh.teaching.service.StudentService;
import com.gzh.teaching.service.dto.GetReportOut;
import com.gzh.teaching.service.dto.GetWorkOut;
import com.gzh.teaching.service.dto.PickCourseOut;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@Slf4j
@RequestMapping("/v1/api/stu")
@RestController
public class StudentController {
  @Autowired
  private StudentService studentService;

  @PostMapping("/pickCourse")
  @CheckToken
  public ResponseEntity<?> pickCourse( @RequestBody PickCourseParam param) {
    Integer userId = RequestContextUtil.getCurrentUserId();
    studentService.pickCourse(param.paramToIn(userId));
    return Result.ok();
  }

  @GetMapping("/getPickCourse")
  @CheckToken
  public ResponseEntity<?> getPickCourse(PickCourseParam param) {
    Integer userId = RequestContextUtil.getCurrentUserId();
    List<PickCourseOut> out = studentService.getPickCourse(param.paramToIn(userId));
    return Result.ok(out);
  }

  @GetMapping("/getNormalWork")
  @CheckToken
  public ResponseEntity<?> getNormalWork(GetJobParam param) {
    Integer userId = RequestContextUtil.getCurrentUserId();
    List<GetJobOut> list =studentService.getNormalWork(param.paramToIn(userId));
    return Result.ok(list);
  }

  @GetMapping("/getWork")
  @CheckToken
  public ResponseEntity<?> getWork(GetJobParam param) {
    Integer currentUserId = RequestContextUtil.getCurrentUserId();
    GetWorkOut out =studentService.getWork(param.paramToIn(currentUserId));
    return Result.ok(out);
  }

  @GetMapping("/getReport")
  @CheckToken
  public ResponseEntity<?> getReport(GetJobParam param) {
    Integer currentUserId = RequestContextUtil.getCurrentUserId();
    GetReportOut out =studentService.getReport(param.paramToIn(currentUserId));
    return Result.ok(out);
  }

  @PostMapping("/saveReportAnswer")
  @CheckToken
  public ResponseEntity<?> saveReport( @RequestBody SaveReportParam param) {
    Integer userId = RequestContextUtil.getCurrentUserId();
    studentService.saveReport(param.paramToIn(userId));
    return Result.ok();
  }

  @PostMapping("/saveWorkAnswer")
  @CheckToken
  public ResponseEntity<?> saveWorkAnswer( @RequestBody SaveWorkAnswerParam param) {
    Integer userId = RequestContextUtil.getCurrentUserId();
    studentService.saveWorkAnswer(param.paramToIn(userId));
    return Result.ok();
  }

  @PostMapping("/checkIn")
  public ResponseEntity<?> checkIn( @RequestBody @Valid CheckInParam param) {
    studentService.checkIn(param);
    return Result.ok();
  }
}
